/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.platform.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.platform.dto.EquipmentRuningStatePageListDTO;
import org.springblade.modules.platform.entity.EquipmentRuningState;
import org.springblade.modules.platform.mapper.EquipmentRuningStateMapper;
import org.springblade.modules.platform.service.IEquipmentRuningStateService;
import org.springblade.modules.platform.vo.EquipmentRuningStateListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  服务实现类
 *
 * @author BladeX
 * @since 2020-12-15
 */
@Service
@Slf4j
public class EquipmentRuningStateServiceImpl extends ServiceImpl<EquipmentRuningStateMapper, EquipmentRuningState> implements IEquipmentRuningStateService {

    @Override
    public Integer insertEquipmentRuningState(EquipmentRuningState equipmentRuningState) {
        return baseMapper.insertEquipmentRuningState(equipmentRuningState);
    }


    @Override
    public EquipmentRuningStateListVO selectEquipmentRuningStateListVOByPage(EquipmentRuningStatePageListDTO equipmentRuningStatePageListDTO) {
        Integer curPage = ((equipmentRuningStatePageListDTO.getCurrent()==null
                || equipmentRuningStatePageListDTO.getCurrent()==0?1:equipmentRuningStatePageListDTO.getCurrent())-1) * (equipmentRuningStatePageListDTO.getSize()==null?10:equipmentRuningStatePageListDTO.getSize());
        equipmentRuningStatePageListDTO.setCurrent(curPage);
        Integer integer = baseMapper.selectListCount(equipmentRuningStatePageListDTO);
        EquipmentRuningStateListVO equipmentRuningStateListVO = new EquipmentRuningStateListVO();
        equipmentRuningStateListVO.setTotal(Long.parseLong(integer.toString()));
        if(integer > 0){
            List<EquipmentRuningState> equipmentRuningStateS = baseMapper.selectListPage(equipmentRuningStatePageListDTO);
            equipmentRuningStateListVO.setJsonTextList(equipmentRuningStateS);
        }
        return equipmentRuningStateListVO;
    }
}
